﻿using Candy.Infrastructure;
using Candy.Model;
using Candy.Web.Data;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace Candy.ViewModel
{
    public class CreateProjectViewModel : ViewModelBase
    {

        private ProjectEditViewModel _project;
        public ProjectEditViewModel Project
        {
            get
            {
                return _project;
            }
            set
            {
                _project = value;
                RaisePropertyChanged("Project");
            }
        }

        private INavigationService _navigationService;
        private IDataService _dataService;
        public CreateProjectViewModel(IDataService dataService, INavigationService navService)
        {
            _dataService = dataService;
            _navigationService = navService;
        
        }

        private RelayCommand _init;
        public RelayCommand Init
        {
            get
            {
                return _init ?? (_init = new RelayCommand(ExecInit, CanInit));
            }
        }

        /// <summary>
        /// Checks whether the Init command is executable
        /// </summary>
        private bool CanInit()
        {
            return true;
        }

        /// <summary>
        /// Executes the Init command 
        /// </summary>
        private void ExecInit()
        {
            Project = new ProjectEditViewModel(_dataService, _navigationService, new ProjectDto(), true);
            Project.Edit.Execute(null);
        }
    }
}
